home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Utilities / Programming / EnterAct 3.5 / hAWK project / AWK Source / MSG.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-22  |  2.7 KB  |  104 lines  |  [TEXT/TOPC]

  1. /*
  2.  * msg.c - routines for error messages
  3.  */
  4.  
  5. /* Copyright © 1986, 1988, 1989 1991 the Free Software Foundation, Inc.
  6.  *         This file is part of GAWK, the GNU implementation of the
  7.  * AWK Progamming Language, modified for the Macintosh (also called hAWK).
  8.  *         GAWK is free software; you can redistribute or modify
  9.  * it under the terms of the GNU General Public License as published by
  10.  * the Free Software Foundation; either version 1, or any later version.
  11.  *         GAWK is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14.  * GNU General Public License for more details.
  15.  *         You should have received a copy of the GNU General Public License
  16.  * along with GAWK; see the file "COPYING hAWK". If not, write to
  17.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  * Modified for THINK C 4 on the Macintosh by Ken Earle (Dynabyte) Aug 1991.
  19.  */
  20.  
  21. #include "AWK.H"
  22.  
  23. /* Mac note, error message routines are not that great at the
  24. moment (ie barely adequate), this will improve when time permits. */
  25.  
  26. static void err(char *s, char *msg, va_list *argp);
  27. void msg(char *va_alist, ...);
  28. void warning(char *va_alist, ...);
  29. void fatal(char *va_alist, ...);
  30.  
  31. /* these two are reinited in main */
  32. short sourceline = 0;
  33. char *source = NULL;
  34.  
  35. /* VARARGS2 */
  36. static void err(char *s, char *msg, va_list *argp)
  37. {
  38.     short line;
  39.     char *file;
  40.  
  41.     (void) fprintf(stderr, "%s: %s ", myname, s);
  42.     vfprintf(stderr, msg, *argp);
  43.     (void) fprintf(stderr, "\n");
  44.     line = (short) FNR_node->var_value->numbr;
  45.     if (line) {
  46.         (void) fprintf(stderr, " input line number %d", line);
  47.         file = FILENAME_node->var_value->stptr;
  48.         if (file && !STREQ(file, "-"))
  49.             (void) fprintf(stderr, ", file `%s'", file);
  50.         (void) fprintf(stderr, "\n");
  51.     }
  52.  
  53.     if (sourceline) {
  54.         (void) fprintf(stderr, " source line number %d", sourceline);
  55.         if (source)
  56.             (void) fprintf(stderr, ", file `%s'", source);
  57.         (void) fprintf(stderr, "\n");
  58.     }
  59.  
  60. }
  61.  
  62. /*VARARGS0*/
  63. void msg(char *va_alist, ...)
  64. {
  65.     va_list args;
  66.     //char *mesg;
  67.  
  68.     va_start(args, va_alist);
  69.     //mesg = va_arg(args, char *);
  70.     //err("", mesg, &args);
  71.     err("", va_alist, &args);
  72.     va_end(args);
  73. }
  74.  
  75. /*VARARGS0*/
  76. void warning(char *va_alist, ...)
  77. {
  78.     va_list args;
  79.     //char *mesg;
  80.  
  81.     va_start(args, va_alist);
  82.     //mesg = va_arg(args, char *);
  83.     //err("warning:", mesg, &args);
  84.     err("warning:", va_alist, &args);
  85.     va_end(args);
  86. }
  87.  
  88. /*VARARGS0*/
  89. void fatal(char *va_alist, ...)
  90. {
  91.     va_list args;
  92.     //char *mesg;
  93.  
  94.     va_start(args, va_alist);
  95.     //mesg = va_arg(args, char *);
  96.     //err("fatal error:", mesg, &args);
  97.     err("fatal error:", va_alist, &args);
  98.     va_end(args);
  99. #ifdef DEBUG
  100.     abort();
  101. #endif
  102.     exit(1);
  103. }
  104.